/**
 * Created by Administrator on 14-4-15.
 */
Ext.define("cloud.api.Util", {
    alternateClassName: "u",
    statics: {
        api_url: 'http://192.168.99.35/cloud/1',
        /**
         * 重载跳转方法
         */
        gotoFn: function () {
            var l = arguments.length;
            var activeItem = Ext.Viewport.getActiveItem(),
                requestItem = l == 1 ? arguments[0] : getPreviousItem(),//1
                directionStr = l == 1 ? "left" : "right";//2
            if (l != 1) {
                Ext.Viewport.animateActiveItem(requestItem, {type: "slide", direction: directionStr, listeners: {
                    animationend: function (slide) {
                        Ext.Viewport.remove(activeItem, true);
                    }
                }});
            } else {
                Ext.Viewport.animateActiveItem(requestItem, {type: "slide", direction: directionStr});
                return false;
            }
        },
        //保存value 永久保存，即使浏览器关闭
        localSave: function (key, value) {
            localRemove(key);
            localStorage.setItem(key, value);
        },
        //获取value
        localGet: function (key) {
            return localStorage.getItem(key);
        },
        //删除键值
        localRemove: function (key) {
            localStorage.removeItem(key);
        },
        getPreviousItem: function () {
            var innerItems = Ext.Viewport.getInnerItems();
            return innerItems[innerItems.length - 2];
        },
        //上传图片
        uploadImgFn:function(url,file,backFn){
            var backthis=this;
            var formdata = new FormData();
            formdata.append("Filedata", file);
            var http = new XMLHttpRequest();
            if (http.upload && http.upload.addEventListener) {
                // Response handler
                http.onreadystatechange = function (e) {
                    if (this.readyState == 4) {
                        if (this.status == 200) {

                        }
                    }
                };
                // Error handler
                http.upload.onerror = this.actionfailure;
            }
            // Send form with file using XMLHttpRequest POST request
            http.open('POST', GLOBAL.api_url + 'attachment_upload&updatatype=adpic');
            http.send(formdata);
        },
        actionfailure: function () {//请求失败时执行操作
            Ext.Viewport.unmask();
            Ext.Msg.alert('请求失败', '服务器维护中....');
        }
    }
})